<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @property bool $hot 热门:1=是,2=否
 * @property bool $solely 独家合作:1=是,2=否
 * @property bool $status 状态:1=待审核,2=待签署合同,3=驳回,4=等待排期,5=等待上线,6=上线
 * @property bool $type 类型:1=免费,2=VIP,3=付费
 * @property int $class_id 分类
 * @property int $deletetime
 * @property int $id
 * @property int $length 视频时长
 * @property int $like 点赞数量
 * @property int $user_id 用户
 * @property string $content 影片简介
 * @property string $contract 合同
 * @property string $copyrightimages 版权声明
 * @property string $createtime
 * @property string $heraldfile 预告片
 * @property string $horizontalimage 横版海报
 * @property string $involveimages 无涉声明
 * @property string $name 影片名称
 * @property string $portraitimages 肖像授权
 * @property string $reason 驳回原因
 * @property string $solelyimages 独家授权签署
 * @property string $style_ids 影片类型
 * @property string $updatetime
 * @property string $verticalimage 竖版海报
 * @property string $videofile 正片
 * @property-read \app\model\MovieCrew[] $crew
 * @property-read \app\model\UserCollect $user_collect
 * @property-read \app\model\UserLike $user_like
 * @property-read mixed $style_ids_text
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 * @mixin \think\Model
 */
class Movie extends Model
{
	use SoftDelete;
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $deleteTime = 'deletetime';
	
	function crew()
	{
		return $this->hasMany(MovieCrew::class,'movie_id');
	}
	
	function getStyleIdsTextAttr($value,$data)
	{
		$value = $value ? $value : ($data['style_ids'] ?? "");
		return MovieStyle::whereIn('id',$value)->column('name');
	}
	
	function userCollect()
	{
		return $this->hasOne(UserCollect::class,'pro_id')->where(['type'=>1]);
	}
	
	function userLike()
	{
		return $this->hasOne(UserLike::class,'pro_id')->where(['type'=>1]);
	}
	
}
